#ifndef NETMANAGER_H
#define NETMANAGER_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QUrl>

#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>

#include <QDebug>
#include <QThread>

#include "Mid_Struct.h"

#include "cutdatamodel.h"

class NetManager : public QObject
{
    Q_OBJECT

public:

    static NetManager* getInstance();

    // 通用字符串拆分函数，从"编号,名称,值"格式中提取值
    QString extractValue(const QString& fieldStr) {
        QStringList parts = fieldStr.split(",");
        if (parts.size() >= 3) {
            return parts[2].trimmed();
        }
        return ""; // 格式不符时返回空字符串
    }


    void processCudata_ChangFeng(const QJsonObject &originalData);

    void processCudata_XinGeEr(const QJsonObject &originalData);

    void processCutData_SuZhi(const QJsonObject &originalData);

    void processCudata_ChuangPin(const QJsonObject &originalData);



signals:

    void send_NetWork_ChangFeng_Url(QString URL);
    void send_NetWork_XinGeEr_Url(QString URL);
    void send_NetWork_SuZhi_Url(QString URL);
    void send_NetWork_ChuangPin_Url(QString URL);

    void send_UpData_ListView_Signal(const QVector<cutData> &data);

public slots:

    void recv_Scanner_Result_ChangFeng_Slots(const QByteArray &result);

    void recv_Scanner_Result_XinGeEr_Slots(const QByteArray &result);

    void recv_Scanner_Result_SuZhi_Slots(const QByteArray &result);

    void recv_Scanner_Result_ChuangPin_Slots(const QByteArray &result);



    void recv_NetWork_ChangFeng_Process_List_Slots(QString URL);

    void recv_NetWork_XinGeEr_Process_List_Slots(QString URL);

    void recv_NetWork_SuZhi_Process_List_Slots(QString URL);

    void recv_NetWork_ChuangPin_Process_List_Slots(QString URL);

private:
    NetManager(QObject *parent = nullptr);
    ~NetManager();
    NetManager(const NetManager&) = delete;
    NetManager& operator=(const NetManager) = delete;

    QNetworkAccessManager* m_NetManager = nullptr;

    QVector<cutData> aggregatedData;  // 聚合后数据（支持数组式访问）

    CutDataModel* model = nullptr;
};


#endif // NETMANAGER_H
